﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Audio;
using System.IO;

namespace Pongster
{
    public struct Settings
    {

        public static int screenWidth = 1280;
        public static int screenHeight = 720;
        public static int screenIndex = 1;

        public const int basescreenWidth = 1920;
        public const int basescreenHeight = 1080;

        public static bool screenMode = false;
        public static int screenModeIndex = 0;

        public static Vector2 aspectRatio = Vector2.Zero;

        public static float musicVolume = 0.2f;
        public static float soundVolume = 0.3f;

        public static void Init(int width, int height, int index, bool mode, int modeindex, int mvolume, int svolume)
        {
            screenWidth = width;
            screenHeight = height;
            screenIndex = index;
            screenMode = mode;
            screenModeIndex = modeindex;
            musicVolume = (float)(mvolume / 10f);
            soundVolume = (float)(svolume / 10f);
        }


        public static void Update(GameTime gameTime)
        {
            soundVolume = MathHelper.Clamp(soundVolume, 0f, 1f);
            musicVolume = MathHelper.Clamp(musicVolume, 0f, 1f);

            MediaPlayer.Volume = musicVolume;
            SoundEffect.MasterVolume = soundVolume;

            double aspectratio = ((double)screenWidth / (double)screenHeight);
            int height = (int)(screenWidth * aspectratio);

            if ((float)screenWidth / screenHeight < 1.6f)
                    aspectRatio = new Vector2(0, screenHeight - (int)(height / 2.22));
                else
                    aspectRatio = Vector2.Zero;

        }

        public static void SaveSettingsFile()
        {
            string[] settingsInformation = new string[7];
            settingsInformation[0] = Convert.ToString(Settings.screenWidth);
            settingsInformation[1] = Convert.ToString(Settings.screenHeight);
            settingsInformation[2] = Convert.ToString(Settings.screenIndex);
            settingsInformation[3] = Convert.ToString(Settings.screenMode);
            settingsInformation[4] = Convert.ToString(Settings.screenModeIndex);
            settingsInformation[5] = Convert.ToString(Settings.musicVolume * 10);
            settingsInformation[6] = Convert.ToString(Settings.soundVolume * 10);
            File.WriteAllLines("settings.txt", settingsInformation);
        }

    }
}
